package com.huawei.fastengine.fastview;

import android.content.Context;
import android.util.Log;
import com.huawei.fastengine.fastview.download.utils.log.FastViewLogUtils;
import com.huawei.secure.android.common.SecureSSLSocketFactory;
import com.huawei.secure.android.common.ssl.SecureX509TrustManager;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import javax.net.ssl.HttpsURLConnection;
import o.fuv.b;

public class HttpsSetting {
    private static final String TAG = "HttpsSetting";

    private static SecureSSLSocketFactory get(Context context) throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException, IllegalAccessException {
        return SecureSSLSocketFactory.getInstance(context);
    }

    public static void initHttpsURLConnection(HttpsURLConnection httpsURLConnection, Context context) {
        try {
            httpsURLConnection.setSSLSocketFactory(get(context));
            httpsURLConnection.setHostnameVerifier(SecureSSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
        } catch (IOException e) {
            FastViewLogUtils.w(TAG, "IOException!");
        } catch (NoSuchAlgorithmException e2) {
            FastViewLogUtils.w(TAG, "NoSuchAlgorithmException!");
        } catch (CertificateException e3) {
            FastViewLogUtils.w(TAG, "CertificateException!");
        } catch (KeyStoreException e4) {
            FastViewLogUtils.w(TAG, "KeyStoreException!");
        } catch (UnrecoverableKeyException e5) {
            FastViewLogUtils.w(TAG, "UnrecoverableKeyException!");
        } catch (KeyManagementException e6) {
            FastViewLogUtils.w(TAG, "KeyManagementException!");
        } catch (IllegalAccessException e7) {
            FastViewLogUtils.w(TAG, "IllegalAccessException!");
        }
    }

    public static void initSSLSocket(b bVar, Context context) {
        if (context != null) {
            try {
                bVar.ॱ(com.huawei.secure.android.common.ssl.SecureSSLSocketFactory.getInstance(context.getApplicationContext()), new SecureX509TrustManager(context.getApplicationContext()));
                bVar.ˊ(com.huawei.secure.android.common.ssl.SecureSSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
            } catch (Exception e) {
                Log.e(TAG, "init ok http ssl socket failed." + e.getMessage());
            }
        }
    }
}
